<?php
/******************************************************************************
 *
 *    OpenZoowa - Web App to manage events
 *    Copyright (C) 2008 Jesus Ruiz-Ayucar
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Affero General Public License as
 *    published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *****************************************************************************/
   class AjaxController {
      public function regions() {
         require_once(modelspath.'region.php');

         header('Content-Type: text/xml; charset=utf-8');
         $xmlString .= '<root>';
         if (isset($_GET['country'])) {
            $xmlString .= '<country id="' . $_GET['country'].'"/>';
            $regions = Region::getList($_GET['country']);
            foreach($regions as $region) {
                     $xmlString .= '<region id="'.$region->getId().'" ';
                     $xmlString .= 'name="'.$region->getName().'" />';
            }
         }
         $xmlString .= '</root>';
         echo '<?xml version="1.0" encoding="utf-8"?>';
         echo $xmlString;
      }

      public function cities() {
         require_once(modelspath.'city.php');

         header('Content-Type: text/xml; charset=utf-8');
         $xmlString .= '<root>';
         if (isset($_GET['region'])) {
            $xmlString .= '<region id="' . $_GET['region'].'"/>';
            $cities = City::getList($_GET['region']);
            foreach($cities as $city) {
                     $xmlString .= '<city id="'.$city->getId().'" ';
                     $xmlString .= 'name="'.$city->getName().'" />';
            }
         }
         $xmlString .= '</root>';
         echo '<?xml version="1.0" encoding="utf-8"?>';
         echo $xmlString;
      }
   }
?>